<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>js数组之追加元素</title>
</head>
<body>
  <ul>
    <li>除之前利用展开元素来追加元素外，还可使用push来追加多个元素</li>
    <li>利用push追加将改变原有数组，且返回结果是追加后的数组长度</li>
  </ul>
  <script>
    const arr1 = [1, 2, 3, 4], arr2 = [5, 6]
    console.log([...arr1, ...arr2])             // [1, 2, 3, 4, 5, 6]
    console.log(arr1.push('Miracle', ...arr2))  // 7, push返回结果是追加后的数组长度
    console.log(arr1)                           // [1, 2, 3, 4, 'Miracle', 5, 6]
    function randomArray(start, end) {
      const arr = []
      for (let i = start; i <= end; i++) {
        arr.push(i)
      }
      return arr
    }
    console.log(randomArray(1, 10))  // [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  </script>
</body>
</html>